package com.dream.qudouapp.activity;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.qudouapp.R;

/**
 * 对标题的一些操作
 * 
 * @author Administrator
 * 
 */
public class BaseTop {

	private Activity activity;
	private ImageView imageleft, imageright;
	private TextView centertext;

	/**
	 * 构造函数
	 * 
	 * @param activity
	 */
	public BaseTop(Activity activity) {
		this.activity = activity;
		View view = LayoutInflater.from(activity).inflate(R.layout.top, null);
		getViewsTop(view);
	}

	/**
	 * 获取组件
	 * 
	 * @param view
	 */
	private void getViewsTop(View view) {
		imageleft = (ImageView) view.findViewById(R.id.top_leftimage);
		imageright = (ImageView) view.findViewById(R.id.top_rightimage);
		centertext = (TextView) view.findViewById(R.id.top_centertext);

	}

	/**
	 * 设置标题左边图片隐藏显示
	 * 
	 * @param visible
	 */
	public void setLeftVisible(int visible) {
		imageleft.setVisibility(visible);
	}

	/**
	 * 设置标题右边图片隐藏显示
	 * 
	 * @param visible
	 */
	public void setRightVisible(int visible) {
		imageright.setVisibility(visible);
	}

	/**
	 * 设置标题隐藏显示
	 * 
	 * @param visible
	 */
	public void setCenterVisible(int visible) {
		centertext.setVisibility(visible);
	}

	/**
	 * 设置左边图片
	 * 
	 * @param drawble
	 */
	public void setLeftSrcImage(int drawble) {
		imageleft.setImageResource(drawble);
	}

	/**
	 * 设置右边图片
	 * 
	 * @param drawble
	 */
	public void setRightSrcImage(int drawble) {
		imageright.setImageResource(drawble);
	}

	/**
	 * 设置标题文字
	 * 
	 * @param string
	 */
	public void setCenterVisible(String string) {
		centertext.setText(string);
	}

	/**
	 * 设置左边点击事件
	 * 
	 * @param cls
	 */
	public void setLeftClick(@SuppressWarnings("rawtypes") final Class cls) {
		imageleft.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				activity.startActivity(new Intent(activity, cls));
			}
		});
	}

	/**
	 * 设置右边点击事件
	 * 
	 * @param cls
	 */
	public void setRightClick(@SuppressWarnings("rawtypes") final Class cls) {
		imageright.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				activity.startActivity(new Intent(activity, cls));
			}
		});
	}

}
